// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;

namespace SnapObjects.Data.DB2
{
    internal class DB2SqlStatementFactory : SqlStatementFactory
    {
        public DB2SqlStatementFactory(ISqlGenerationHelper helper, ITypeMapper mapper)
            : base(helper, mapper)
        {
        }

        public override ISqlBuilderParser GetBuilderParser(SqlStatementType statementType)
        {
            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    return new DB2QueryBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.SqlRaw:
                {
                    return new DB2RawBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Insert:
                {
                    return new DB2InsertBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Update:
                {
                    return new DB2UpdateBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Delete:
                {
                    return new DB2DeleteBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Procedure:
                {
                    return new DB2ProcedureBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Condition:
                {
                    return new DB2ConditionBuilderParser(this, _helper, _mapper);
                }
                case SqlStatementType.Function:
                {
                    return new DB2FunctionBuilderParser(this, _helper, _mapper);
                }
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }
        }

        public override ISqlStatementGenerator GetSqlGenerator(SqlStatementType statementType)
        {
            ISqlStatementGenerator generator;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    generator = new DB2SqlSelectStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    generator = new DB2SqlInsertStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Update:
                {
                    generator = new DB2SqlUpdateStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    generator = new DB2SqlDeleteStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    generator = new DB2SqlProcedureStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Condition:
                {
                    generator = new DB2SqlConditionStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    generator = new DB2SqlRawStatementGenerator(this, _helper, _mapper);
                }
                break;
                case SqlStatementType.Function:
                {
                    generator = new DB2SqlFunctionStatementGenerator(this, _helper, _mapper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return generator;
        }

        public override ISqlStatementParser GetSqlParser(SqlStatementType statementType)
        {
            ISqlStatementParser parser;

            switch (statementType)
            {
                case SqlStatementType.Select:
                {
                    parser = new DB2SqlSelectStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Delete:
                {
                    parser = new DB2SqlDeleteStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Update:
                {
                    parser = new DB2SqlUpdateStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Insert:
                {
                    parser = new DB2SqlInsertStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Procedure:
                {
                    parser = new DB2SqlProcedureStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.SqlRaw:
                {
                    parser = new DB2SqlRawStatementParser(this, _helper);
                }
                break;
                case SqlStatementType.Function:
                {
                    parser = new DB2SqlFunctionStatementParser(this, _helper);
                }
                break;
                default:
                {
                    throw new NotSupportedException(statementType.ToString());
                }
            }

            return parser;
        }
    }
}
